package com.example.demo.entity;

public final class StudentId {

    private final String first;

    private final Integer last;

    public StudentId(String first, Integer last) {
        this.first = first;
        this.last = last;
    }


    @Override
    public String toString() {
        return first+last;
    }

    public static StudentId valueOf(String id){
        if (id.length() != 4) {
            System.out.println("wrong param");
            return null;
        }
        String first = id.substring(0,1);
        String tempLast = id.substring(1);
        int last;
        try {
             last = Integer.parseInt(tempLast);
        }catch (Exception e){
            System.out.println("wrong param");
            return null;
        }
        return new StudentId(first,last);
    }
}
